package com.thinkfit.jy.presenter;

import com.common.lib.bean.UserBean;
import com.common.lib.bean.VideoBean;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.BasePresenter;
import com.common.lib.network.HttpListener;
import com.common.lib.network.HttpMethods;
import com.common.lib.network.HttpObserver;
import com.thinkfit.jy.R;
import com.thinkfit.jy.contract.VideoCourseDetailContract;
import com.thinkfit.jy.utils.DeviceTypeUtils;
import com.thinkfit.jy.utils.LoadViewUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class VideoCourseDetailPresenter extends BasePresenter<VideoCourseDetailContract.View> implements VideoCourseDetailContract.Presenter {

    public VideoCourseDetailPresenter(@NotNull VideoCourseDetailContract.View rootView) {
        super(rootView);
    }


    @Override
    public void getVideoCourseDetail(int videoId,int vType) {
        UserBean myInfo = DataManager.Companion.getInstance().getMyInfo();
        System.out.println("ddddddddddddddddddddddd  videoId  : "+videoId);
        HttpMethods.Companion.getInstance().videoDetail(
                myInfo == null ? "" : myInfo.getUid(),
                vType, videoId,
                new HttpObserver(false, getRootView(), new HttpListener<VideoBean>() {
                    @Override
                    public void onSuccess(@Nullable VideoBean bean) {
                        if (getRootView() == null) {
                            return;
                        }
                        System.out.println("ddddddddddddddddddddddd   VideoBean : "+bean.toString());
                        getRootView().getVideoCourseDetailSuccess(bean);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(code, msg);
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(-1, "");
                    }
                }, getCompositeDisposable()));
    }

    @Override
    public void getLiveVideoDetail(int videoId,int vType) {
        UserBean myInfo = DataManager.Companion.getInstance().getMyInfo();
        HttpMethods.Companion.getInstance().videoDetail(
                myInfo == null ? "" : myInfo.getUid(),
                vType, videoId,
                new HttpObserver(false, getRootView(), new HttpListener<VideoBean>() {
                    @Override
                    public void onSuccess(@Nullable VideoBean bean) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().getLiveVideoDetailSuccess(bean);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(code, msg);
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(-1, "");
                    }
                }, getCompositeDisposable()));
    }


    @Override
    public void addcollect(int vid,int type){
        HttpMethods.Companion.getInstance().addcollect(
                DeviceTypeUtils.getDeviceType(),
                vid,
                DataManager.Companion.getInstance().getMyInfo().getUid(),type,
                new HttpObserver(false, getRootView(), new HttpListener<Object>() {
                    @Override
                    public void onSuccess(@Nullable Object bean) {
                        LoadViewUtils.getInstance().goneLayout();
                        getRootView().addcollectSuccess();
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                    }
                }, getCompositeDisposable()));
    }


    @Override
    public void addVideoRecord(int videoId) {
        HttpMethods.Companion.getInstance().addVideoRecord(
                DataManager.Companion.getInstance().getMyInfo().getUid(),
                videoId, 1,
                new HttpObserver(false, getRootView(), new HttpListener<Object>() {
                    @Override
                    public void onSuccess(@Nullable Object bean) {
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                    }
                }, getCompositeDisposable()));
    }

    @Override
    public void getAdvert() {

    }

    @Override
    public void getVideoList(int type) {

    }

}
